window.addEventListener("load", function () {
	console.log($(".s-title a"));
	$("form")[0].style.zIndex = "90";
	$(".s-title a").forEach(function (v, i) {
		v.addEventListener("click", function () {
			// 排他思想, 先全部移除激活
			$(".s-title a").forEach(function (item) {
				item.classList.remove("active");
			});
			//再添加激活
			this.classList.add("active");

			$("form").forEach(function (each) {
				each.style.zIndex = "0";
			});

			$("form")[i].style.zIndex = "90";
		});

		console.log("a", $(".s-title a"));
		console.log("form", $("form"));
	});

	// 用户名
	const regex = /^[a-zA-Z0-9]{6,20}$/;
	// 密码
	const regex2 = /^[a-zA-Z]\w{5,17}$/;

	// 用户名
	$("#username").addEventListener("blur", function () {
		if (regex.test($("#username").value)) {
			$("#username").style.borderBottom = "1px solid black";
			$("#username").nextElementSibling.textContent = "";
		} else {
			$("#username").style.borderBottom = "1px solid red";
			$("#username").nextElementSibling.textContent = "请输入用正确的户名";
			$("#username").nextElementSibling.style.color = "red";
		}
	});

	// 密码
	$("#password").addEventListener("blur", function () {
		if (regex2.test($("#password").value)) {
			$("#password").style.borderBottom = "1px solid #000";
			$("#password").nextElementSibling.textContent = "";
		} else {
			$("#password").style.borderBottom = "1px solid red";
			$("#password").nextElementSibling.textContent = "请输入用正确的密码";
			$("#password").nextElementSibling.style.color = "red";
		}
	});

	// 提交时;
	$(".loginB").addEventListener("click", function (e) {
		if (regex.test($("#username").value)) {
			$("#username").style.borderBottom = "1px solid #000";
			$("#username").nextElementSibling.textContent = "";
		} else {
			$("#username").style.borderBottom = "1px solid red";
			$("#username").nextElementSibling.textContent = "请输入用正确的户名";
			$("#username").nextElementSibling.style.color = "red";
			e.preventDefault();
		}
		// 密码
		if (regex2.test($("#password").value)) {
			$("#password").style.borderBottom = "1px solid #000";
			$("#password").nextElementSibling.textContent = "";
		} else {
			$("#password").style.borderBottom = "1px solid red";
			$("#password").nextElementSibling.textContent = "请输入用正确的密码";
			$("#password").nextElementSibling.style.color = "red";
			e.preventDefault();
		}
	});
});
